<template>
  <el-button
    :class="{ button_update: update }"
    :type="type"
    :disabled="!CheckUserAuth() || disabled"
    size="small"
    v-bind="attributes"
  >
    {{ title }}
  </el-button>
</template>
<!--  权限全局按钮  -->
<script setup lang="ts">
  defineProps({
    title: {
      type: String,
      default: '',
    },
    // 按钮样式
    type: {
      type: String,
      default: '',
    },
    // 属性
    attributes: {
      type: Object,
      default: {},
    } as any,
    // 更新样式
    update: {
      type: Boolean,
      default: false,
    },
    // 禁用
    disabled: {
      type: Boolean,
      default: false,
    },
  })

  import { BaseUserInfo } from '~/src/utils/utils'

  const CheckUserAuth = () => {
    const { is_master, menu } = BaseUserInfo()
    const route: any = useRoute()
    /*
      若当前用户是主用户 【全权限】
    */
    if (is_master) return true
    // .all 全部权限 .readonly 只读
    return menu.indexOf(route.name + '.all') > -1
  }
</script>

<style scoped></style>
